/**
 * @Title: index.js
 * @Description: index
 * @author: Fanchao
 * @date: 2020/7/30 11:20 下午
 * @version V1.0
 */
import React, { useState } from 'react';
import styles from './index.less';
import { Input, Button, message } from 'antd';
import PropTypes from 'prop-types';

const FilterByKeyWord = ({ onSearch, onReset }) => {
    const [keyWord, setKeyWord] = useState('');
    return (
        <div className={styles.filterContainer}>
            <div className={styles.title}>关键字搜索</div>
            <div className={styles.formSection}>
                <Input
                    className={styles.keyWord}
                    placeholder="请输入关键字"
                    value={keyWord}
                    onChange={(e) => {
                        setKeyWord(e.target.value);
                    }}
                />
                <Button
                    className={styles.marginLeft}
                    type="primary"
                    onClick={() => {
                        if (!keyWord) {
                            message.warning('请输入要查询的内容');
                            return;
                        }
                        onSearch(keyWord);
                    }}
                >
                    查询
                </Button>
                <Button
                    className={styles.marginLeft}
                    onClick={() => {
                        onReset('');
                        setKeyWord('');
                    }}
                >
                    重置
                </Button>
            </div>
        </div>
    );
};
FilterByKeyWord.propTypes = {
    onSearch: PropTypes.func.isRequired,
    onReset: PropTypes.func.isRequired,
};
export default FilterByKeyWord;
